Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added sequencer set polling and consensus msgs queue #1144

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

keruch
Copy link
Contributor

@keruch keruch commented Oct 16, 2024

PR Standards

ADR links

  1. https://www.notion.so/dymension/ADR-x-Sequencer-Reward-Address-On-Rollapp-da84af6888c141d0a4c1a8df256a5025
  2. https://www.notion.so/dymension/ADR-Whitelisted-Relayer-Fee-Exemption-in-Rollapp-104a4a51f86a80e8ad94c916c87deb17

Closes dymensionxyz/dymension#1248 and dymensionxyz/dymension#1226

For Author:

  • Targeted PR against correct branch
  • included the correct type prefix in the PR title
  • Linked to Github issue with discussion and accepted design
  • Targets only one github issue
  • Wrote unit and integration tests
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • confirmed all author checklist items have been addressed

After reviewer approval:

  • In case targets main branch, PR should be squashed and merged.
  • In case PR targets a release branch, PR should be rebased.

@keruch keruch self-assigned this Oct 16, 2024
@keruch keruch requested a review from a team as a code owner October 16, 2024 18:13
@danwt
Copy link
Contributor

danwt commented Oct 17, 2024

linter

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only did a quick scan, but might it be better to use an off shelf queue?
This is a ubiquitious data structure with numerous library implementations
e.g .https://github.com/liyue201/gostl?tab=readme-ov-file#queue

@keruch
Copy link
Contributor Author

keruch commented Oct 17, 2024

ubiquitious data structure with numerous library implementations

@danwt i think that's why it's easy to implement and maintain. external libraries introduce extra dependencies that we need to maintain. what if the library will become abandoned or archived? or if someday someone puts some malicious stuff in there and it goes unnoticed? plus usually these libs have a lot of overcomplicated logic that we don't need and won't ever use. 

in our case, we need a simple queue with very limited functionality, so i think it's not a problem to implement it ourselves using native go.

@keruch keruch changed the base branch from kirill/1248-sequencer-reward-addr to main October 18, 2024 09:08
@keruch keruch requested a review from danwt October 18, 2024 09:14
Copy link
Contributor

@omritoptix omritoptix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job! a few comments/suggestions.

@@ -115,14 +115,9 @@ func (e *Executor) CreateBlock(
maxBlockDataSizeBytes = min(maxBlockDataSizeBytes, uint64(max(minBlockMaxBytes, state.ConsensusParams.Block.MaxBytes)))
mempoolTxs := e.mempool.ReapMaxBytesMaxGas(int64(maxBlockDataSizeBytes), state.ConsensusParams.Block.MaxGas)

var consensusAnyMessages []*proto.Any
var consensusMsgs []proto2.Message
if e.consensusMessagesStream != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in what situation is this nil? possibly redundnat validatoin?

@@ -39,6 +37,15 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context, bytesProducedC chan int)
select {
case <-ctx.Done():
return nil

case update := <-sequencerSetUpdates:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the location of this logic in the produce block loop.
thinking if there is a better place. maybe it's own goroutine.

@@ -229,12 +226,18 @@ func (m *Manager) Start(ctx context.Context) error {
// channel to signal sequencer rotation started
rotateSequencerC := make(chan string, 1)

// channel for sequencer set updates
sequencerSetUpdatesC := make(chan []types.Sequencer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can move all this polling logic and channel initialization to a different method to not bloat the Start?
related to my comment that not sure why the sequecer updates signal is in the block production loop

@@ -134,13 +197,36 @@ func (s *SequencerSet) GetByConsAddress(cons_addr []byte) *Sequencer {
return nil
}

// SequencerListRightOuterJoin returns a set of sequencers that are in B but not in A.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SequencerListRightOuterJoin returns a set of sequencers that are in B but not in A.
// SequencerListRightOuterJoin returns a set of sequencers that are in B but not in A.
// sequencer is identified by a hash of all of it's fields.

@@ -134,13 +197,36 @@ func (s *SequencerSet) GetByConsAddress(cons_addr []byte) *Sequencer {
return nil
}

// SequencerListRightOuterJoin returns a set of sequencers that are in B but not in A.
// CONTRACT: both A and B do not have duplicates!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow this. why is this assumption necessary? worst case diff is empty no?

// and is not thread-safe. Returns errors on serialization issues.
func (m *Manager) HandleSequencerSetUpdate(newSet []types.Sequencer) error {
// find new (updated) sequencers
newSequencers := types.SequencerListRightOuterJoin(m.State.Sequencers.Sequencers, newSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if newSequencers is empty? probably worth returning early.

@omritoptix omritoptix marked this pull request as draft October 20, 2024 16:17
@omritoptix
Copy link
Contributor

blocked by #1149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sequencer Reward Address On Rollapp - Impl
3 participants